package com.ytc.learning.controller;

import com.ytc.commons.model.dto.LearningProgressDto;
import com.ytc.commons.model.dto.PageRequest;
import com.ytc.commons.model.dto.RecordDto;
import com.ytc.commons.model.vo.CourseRecordVo;
import com.ytc.commons.model.vo.ResourceVo;
import com.ytc.commons.model.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;
import com.ytc.learning.service.CourseRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 选课记录前端控制器
 * </p>
 *
 * @author jiuye145
 */
@Slf4j
@RestController
@RequestMapping
public class CourseRecordController {

    @Autowired
    private CourseRecordService courseRecordService;

    /*
     * 查询学生对课程的选课记录信息
     * @GET /learnRecords/myCourseRec/{coursePubId}
     * 参数：coursePubId
     * 返回值: ResponseResult<CourseRecordVo>
     * */
    @GetMapping ( "/learnedRecords/myCourseRec/{coursePubId}" )
    public ResponseResult<CourseRecordVo> findRecordByPubId (@PathVariable ( "coursePubId" ) Long coursePubId){
        return courseRecordService.findRecordByPubId(coursePubId);
    }

    /*
     * 保存或者更新选课记录
     *POST courseRecord/saveRecord
     * 请求参数：RecordDto
     * 返回ResponseResult
     * */
    @PostMapping ( "/courseRecord/saveRecord" )
    public ResponseResult saveRecord (@RequestBody RecordDto dto){
        return courseRecordService.saveRecord(dto);
    }

    //获取课程视频播放资源
    //learnedRecords/resource-url
    //查询课程的媒资信息
    @GetMapping ( "/learnedRecords/resource-url" )
    public ResponseResult<ResourceVo> findPlanUrl (Long coursePubId,Long mediaId,Long teachPlanId){
        return courseRecordService.findPlanUrl(coursePubId,mediaId,teachPlanId);
    }

    /*
     * //保存学习进度
     * POST /learningRecords/progress
     * 请求参数：LearningProgressDto
     * 响应 ResponseResult
     * */
    @PostMapping ( "/learnedRecords/progress" )
    public ResponseResult progress (@RequestBody LearningProgressDto dto){
        return courseRecordService.progress(dto);
    }

    @PostMapping ( "/learnedRecords/list" )
    public ResponseResult list (PageRequest request){
        return courseRecordService.MyList(request);
    }


}
